import React from 'react';
import { inject, observer } from 'mobx-react';
import { WeaDialog, WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;
@inject('smsRadioStore')
@observer
class RadioDialog extends React.Component {
  constructor(props) {
    super(props);
  }
  // 渲染流程业务数据
  renderWorkFlowBiz = () => {
    const { smsRadioStore } = this.props;
    const { workFlowBiz } = smsRadioStore;

    if (workFlowBiz) {
      return workFlowBiz.map((val, index) => {
        let valHtml = `<a contenteditable='false' onclick="window.open('/common/chatResource/view.html?resourcetype=0&resourceid=${val.bizid}&isfromchatshare=1&sharer=${val.bizcreater}')"` +
          'href="javascript:void(0);" unselectable="off" contenteditable="false"' +
          'style="cursor:pointer;text-decoration:none !important;margin-right:8px">' +
          `${val.bizname}</a>&nbsp;</br>`;
        return (
          <div className={index == 0 ? 'container-content-Workflow' : 'container-content-Workflow-n'} dangerouslySetInnerHTML={{ __html: valHtml }} />
        );
      });
    }
  }
  // 渲染文档业务数据
  renderDocBiz = () => {
    const { smsRadioStore } = this.props;
    const { docBiz } = smsRadioStore;

    if (docBiz) {
      return docBiz.map((val, index) => {
        let valHtml = `<a contenteditable='false' onclick="ecCom.WeaRichText.openAppLink(this,${val.bizid},37)"` +
          'href="javascript:void(0);" unselectable="off" contenteditable="false"' +
          'style="cursor:pointer;text-decoration:none !important;margin-right:8px">' +
          `${val.bizname}</a>&nbsp;</br>`;
        return (
          <div className={index == 0 ? 'container-content-Workflow' : 'container-content-Workflow-n'} dangerouslySetInnerHTML={{ __html: valHtml }} />
        );
      });
    }
  }
  // 渲染附件业务数据
  renderFileBiz = () => {
    const { smsRadioStore } = this.props;
    const { fileBiz } = smsRadioStore;
    // parent.openFullWindowHaveBar('/spa/document/index.jsp?id=${val.bizid}#/main/document/detail') pc
    if (fileBiz) {
      return fileBiz.map((val, index) => {
        let valHtml = `<a onclick="ecCom.WeaRichText.openAppLink(this,${val.bizid},37)" unselectable="off"` +
          'style="cursor:pointer;text-decoration:none !important;margin-right:8px"' +
          `href="javascript:void(0);" contenteditable="false">${val.bizname}</a>&nbsp;<a unselectable='off' contenteditable='false'` +
          `href='javascript:window.open(\"${val.loadlink}\");void(0)' ` +
          `style='cursor:pointer;text-decoration:none;margin-right:8px'>下载(${val.filesize})</a>&nbsp;</br>`;
        return (
          <div className={index == 0 ? 'container-content-Workflow' : 'container-content-Workflow-n'} dangerouslySetInnerHTML={{ __html: valHtml }} />
        );
      });
    }
  }
  render() {
    const { smsRadioStore } = this.props;
    const { msgDialogItem, msgDialogVisible, closeMsgDialog, workFlowBiz, docBiz, fileBiz } = smsRadioStore;
    const moreBtn = {
      datas: [],
    };
    return (
      <div className="sms-radio">
        <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@16icvv`}
          scalable // 开启放大功能
          style={{ width: 700, height: 400 }}
          hasScroll={true}
          title={getLabel(514516, '广播详情')}
          zIndex={999999}
          icon="icon-coms02-top-news2"
          visible={msgDialogVisible}
          moreBtn={moreBtn}
          onCancel={() => closeMsgDialog()}
        >
          <div id="add" className="sms-radio-dialog-container">
            <div className="container-head">
              <div className="container-title">{msgDialogItem.title}</div>
              <div className="container-info">
                <div className="container-sendInfo">
                  <span>{msgDialogItem.creater}</span>
                  <span className="container-time">{msgDialogItem.createdate}  {msgDialogItem.createtime}</span>
                </div>
              </div>
            </div>
            <div className="container-content" dangerouslySetInnerHTML={{ __html: msgDialogItem.contexts }} />
            <div className="container-content" style={{ display: fileBiz.length > 0 ? 'block' : 'none' }}>
              <span className="icon-coms-currency-Enclosure" title="附件" />
              {this.renderFileBiz()}
            </div>
            <div className="container-content" style={{ display: docBiz.length > 0 ? 'block' : 'none' }}>
              <span className="icon-coms-Journal" title="文档" />
              {this.renderDocBiz()}
            </div>
            <div className="container-content" style={{ display: workFlowBiz.length > 0 ? 'block' : 'none' }}>
              <span className="icon-portal-Workflow-o" title="流程" />
              {this.renderWorkFlowBiz()}
            </div>
          </div>
        </WeaDialog>
      </div>
    );
  }
}

export default RadioDialog;
